package com.huangfu.learning.javabase.java.restructure.polymorphicreplaceswitch.switchcase;

/**
 * Created with IntelliJ IDEA.
 * Author: huangfu.daohui
 * Date: 2018/11/13
 * Time: 10:41
 * Version: 1.0
 * Description:条件表达式（状态模式）
 * 弊端：此时，如果要新加一个职位，那么就必须增加一个状态码，然后在switch语句中，加入该状态码的行为，接着，建立对象的时候，也要使用该状态码。
 **/
public class EmployeeOld {
    private int mType; //类型
    static final int salary = 500; // 薪资
    static final int commission = 500; //提成
    static final int bonus = 1000; //奖金

    static final int ENGINEER = 0; //工程师
    static final int SALESMAN = 1; //销售
    static final int MANAGER = 2; //经理

    public EmployeeOld(int type) {
        this.mType = type;
    }


    // 支付薪资
    int payAmout() {
        switch (mType) {
            case ENGINEER:
                return salary;
            case SALESMAN:
                return salary + commission;
            case MANAGER:
                return salary + bonus;
            default:
                throw new RuntimeException();
        }
    }

    /**
     * 测试
     *
     * @param args
     */
    public static void main(String[] args) {
        EmployeeOld enginer = new EmployeeOld(EmployeeOld.ENGINEER);
        System.out.println("enginer工资为:" + enginer.payAmout());
        EmployeeOld manager = new EmployeeOld(EmployeeOld.MANAGER);
        System.out.println("manager工资为:" + manager.payAmout());
        EmployeeOld salesman = new EmployeeOld(EmployeeOld.SALESMAN);
        System.out.println("salesman工资为:" + salesman.payAmout());
    }
}
